package com.example.projecttwo;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.net.DatagramSocket;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    public TextView text_1event;
    private Button button_1event;
    private Button button_2event;
    private Button button_3event;
    private Button button_4event;
    private Button button_5event;
    private Button button_6event;
    private Button button_7event;
    private Button button_8event;
    private View v;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        text_1event = findViewById(R.id.text_1);
        button_1event = (Button) findViewById(R.id.buttom_1);
        //Activity作为监听器
        button_2event = (Button) findViewById(R.id.buttom_2);
        //匿名内部类实现
        button_3event = (Button) findViewById(R.id.buttom_3);
        //绑定到标签
        button_4event = (Button) findViewById(R.id.buttom_4);
        //内部类实现监听
        button_5event = (Button) findViewById(R.id.buttom_5);
        //外部类
        button_6event = (Button) findViewById(R.id.buttom_6);
        //ButterKnife绑定
        button_7event = (Button) findViewById(R.id.buttom_7);
        button_8event = (Button) findViewById(R.id.buttom_8);

        button_7event.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转页面到
                Intent intent =new Intent(MainActivity .this,ConfigurationTest .class) ;
                startActivity(intent);
            }
        });
        button_8event.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转页面到
                Intent intent =new Intent(MainActivity .this,ProgressDialogTest.class) ;
                startActivity(intent);
            }
        });

        button_2event.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                text_1event.setText("匿名内部类");
            }
        });
        button_4event.setOnClickListener(new OnClick());
        button_1event.setOnClickListener(MainActivity.this);
        button_5event.setOnClickListener(new MyClickListener(MainActivity.this, text_1event));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.buttom_1:
                text_1event.setText("activity作为监听器");
                break;
        }
    }

    class OnClick implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.buttom_4:
                    text_1event.setText("内部类");
                    break;
            }
        }
    }

    public void show(View v) {
        switch (v.getId()) {
            case R.id.buttom_3:
                text_1event.setText("绑定到标签");
                break;
        }
    }

    @butterknife.OnClick (R.id.buttom_6)
    public void changeText( ){
        text_1event .setText("Butterknife绑定");
    }
}
